package com.sv.jm.baselibrary.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.StrictMode;
import android.widget.Space;

/**
 * Created by Administrator on 2017/6/27.
 */

public class DataSaveUtils {
    Context mContext;
    private static DataSaveUtils instance = null;
    static SharedPreferences sp;

    private DataSaveUtils(Context ct) {
        mContext = ct;
    }

    private static SharedPreferences getSP(Context ct) {
        if (null == sp)
            sp = ct.getSharedPreferences("bdhtml", Context.MODE_PRIVATE);
        return sp;
    }

    public static DataSaveUtils getInstance(Context ct) {
        synchronized (DataSaveUtils.class) {
            if (null == instance)
                instance = new DataSaveUtils(ct);
        }
        return instance;
    }

    public DataSaveUtils putString(String key, String value) {
        getSP(mContext).edit().putString(key, value).commit();
        return this;
    }

    public DataSaveUtils putBoolean(String key, boolean value) {
        getSP(mContext).edit().putBoolean(key, value).commit();
        return this;
    }

    public DataSaveUtils putInt(String key, int value) {
        getSP(mContext).edit().putInt(key, value).commit();
        return this;
    }

    public int getInt(String key) {
        return getSP(mContext).getInt(key, -1);
    }

    public String getString(String key) {
        return getSP(mContext).getString(key, "");
    }

    public boolean getBoolean(String key) {
        return getSP(mContext).getBoolean(key, false);
    }
}
